<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商户信息列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i>部门结构
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool menuItem" href="#"
                       onclick="dept()" title="管理部门"><i class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnExpand"
                            title="展开" style="display: none;">
                        <i class="fa fa-chevron-up"></i>
                    </button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse"
                            title="折叠">
                        <i class="fa fa-chevron-down"></i>
                    </button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh"
                            title="刷新部门">
                        <i class="fa fa-refresh"></i>
                    </button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
</div>
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>商户名称：</p> <input type="text" name="merchantName"/> <input
                                type="hidden" id="deptId" name="deptId">
                        </li>
                        <li>
                            <p>商户状态：</p> <select name="merchantStatus"
                                                 th:with="type=${@dict.getType('t_merchant_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <p>审核状态：</p> <select name="examineStatus"
                                                 th:with="type=${@dict.getType('t_examine_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <p>商户属性：</p> <select name="merchantAttribute"
                                                 th:with="type=${@dict.getType('t_merchant_attribute')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li><a class="btn btn-primary btn-rounded btn-sm"
                               onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm"
                               onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()"
               shiro:hasPermission="bussiness:merchantinfo:add"> <i
                    class="fa fa-plus"></i> 添加
            </a> <a class="btn btn-primary btn-edit disabled"
                    onclick="$.operate.editFull()"
                    shiro:hasPermission="bussiness:merchantinfo:edit"> <i
                class="fa fa-edit"></i> 修改
        </a> <a class="btn btn-danger btn-del btn-del disabled"
                onclick="$.operate.removeAll()"
                shiro:hasPermission="bussiness:merchantinfo:remove"> <i
                class="fa fa-remove"></i> 删除
        </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: layout-latest-js"/>
<script th:inline="javascript">
    var examineFlag = [[${@permission.hasPermi('bussiness:merchantinfo:examine')}]];
    var editFlag = [[${@permission.hasPermi('bussiness:merchantinfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bussiness:merchantinfo:remove')}]];
    var merchantStatusDatas = [[${@dict.getType('t_merchant_status')}]];
    var examineStatusDatas = [[${@dict.getType('t_examine_status')}]];
    var merchantAttributeDatas = [[${@dict.getType('t_merchant_attribute')}]];
    var commodityEquityDatas = [[${@dict.getType('t_commodity_equity')}]];
    var prefix = ctx + "bussiness/merchantinfo";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryDeptTree();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "商户信息",
            sortName: "createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'merchantId',
                    title: '商户id',
                    visible: false
                },
                {
                    field: 'merchantName',
                    title: '商户名称'
                },
                {
                    field: 'merchantAddress',
                    title: '商户地址',
                    visible: false
                },
                {
                    field: 'merchantImg',
                    title: '商户图片',
                    formatter: function (value) {
                        if (value) {
                            value = ctx + "profile" + value;
                            return "<img src='"
                                + value
                                + "' style='height: 36px;' target='_blank' tile='点击查看' onclick='$.operate.alertPic(\""
                                + value
                                + "\")'></img>";
                        }
                    }
                },
                {
                    field: 'merchantCreditCode',
                    title: '信用代码',
                    visible: false
                },
                {
                    field: 'merchantLicenseImg',
                    title: '商户营业执照',
                    visible: false,
                    formatter: function (value) {
                        if (value) {
                            value = ctx + "profile" + value;
                            return "<img src='"
                                + value
                                + "' style='height: 36px;' target='_blank' tile='点击查看' onclick='$.operate.alertPic(\""
                                + value
                                + "\")'></img>";
                        }
                    }
                },
                {
                    field: 'merchantStatus',
                    title: '商户状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(merchantStatusDatas, value);
                    }
                },
                {
                    field: 'examineStatus',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(examineStatusDatas, value);
                    }
                },
                {
                    field: 'examineDesc',
                    title: '审核描述',
                    visible: false
                },
                {
                    field: 'merchantAttribute',
                    title: '商户属性',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(merchantAttributeDatas, value);
                    }
                },
                {
                    field: 'commodityEquity',
                    title: '商品权益',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(commodityEquityDatas, value);
                    }
                },
                {
                    field: 'cityName',
                    title: '所在城市'
                },
                {
                    field: 'deptName',
                    title: '所属部门'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    visible: false
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true
                },
                {
                    field: 'updateBy',
                    title: '操作人',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + examineFlag + '" href="javascript:void(0)" onclick="examinePage(\'' + row.merchantId + '\')"><i class="fa fa-credit-card"></i>审核</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.merchantId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.merchantId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function queryDeptTree() {
        var url = ctx + "system/dept/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#deptId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryDeptTree();
    });

    /**
     * 审核页面
     * @param merchantId
     */
    function examinePage(merchantId) {
        $.modal.open("审核商户信息",
            prefix + "/examine/" + merchantId);
    }
</script>
</body>
</html>